package com.mengxuegu.springboot.controller;

import com.alibaba.fastjson.JSON;
import com.mengxuegu.springboot.entities.SpendBean;
import com.mengxuegu.springboot.entities.SpendSearch;
import com.mengxuegu.springboot.service.ItemRepository;
import org.apache.ibatis.annotations.Insert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
public class SpendSearchController {
    @Autowired
    ItemRepository itemRepository;

    Logger logger = LoggerFactory.getLogger(getClass());

    @PostMapping("/addSpend")
    public String addSpend(@RequestBody SpendSearch spendSearch){
        logger.info("新增："+JSON.toJSONString(spendSearch));
        itemRepository.save(spendSearch);
        return "succes";
    }

    @PostMapping("/searchAll")
    public Object searchAll(){
        Iterable<SpendSearch> all = itemRepository.findAll();

//        logger.info("查询结果："+JSON.toJSONString(all));
        return all;
    }


}
